Program to Launch the browser and open a specific URI
```java
// Java Program to Launch the browser
// and open a specific URI
import java.awt.;
import javax.swing.;
import java.awt.event.;
import java.net.;
class desk extends JFrame implements ActionListener {
// frame
static JFrame f;
// Main Method
public static void main(String args[])
{
desk d = new desk();
// create a frame
f = new JFrame("desktop");
// create a panel
JPanel p = new JPanel();
// create a button
JButton b = new JButton("launch");
// add Action Listener
b.addActionListener(d);
p.add(b);
f.add(p);
f.show();
f.setSize(200, 200);
}
// if button is pressed
public void actionPerformed(ActionEvent e)
{
try {
// create a URI
URI u = new URI("www.geeksforgeeks.org");
Desktop d = Desktop.getDesktop();
d.browse(u);
}
catch (Exception evt) {
}
}
}
```
输出:
Program to Launch the mail to a specific URI
```java
// Java Program to Launch the
// mail to a specific URI
import java.awt.;
import javax.swing.;
import java.awt.event.;
import java.net.;
class desk extends JFrame implements ActionListener {
// frame
static JFrame f;
// Main Method
public static void main(String args[])
{
desk d = new desk();
// create a frame
f = new JFrame("desktop");
// create a panel
JPanel p = new JPanel();
// create a button
JButton b = new JButton("launch");
// add Action Listener
b.addActionListener(d);
p.add(b);
f.add(p);
f.show();
f.setSize(200, 200);
}
// if button is pressed
public void actionPerformed(ActionEvent e)
{
try {
URI u = new URI("mailto:contribute@geeksforgeeks.org");
Desktop d = Desktop.getDesktop();
d.mail(u);
}
catch (Exception evt) {
JOptionPane.showMessageDialog(this, evt.getMessage());
}
}
}
```
输出:
Program to open a file
```java
// Java Program to open a file
import java.awt.;
import javax.swing.;
import java.awt.event.;
import java.io.;
import java.net.*;
class desk extends JFrame implements ActionListener {
// frame
static JFrame f;
// Main Method
public static void main(String args[])
{
desk d = new desk();
// create a frame
f = new JFrame("desktop");
// create a panel
JPanel p = new JPanel();
// create a button
JButton b = new JButton("launch");
// add Action Listener
b.addActionListener(d);
p.add(b);
f.add(p);
f.show();
f.setSize(200, 200);
}
// if button is pressed
public void actionPerformed(ActionEvent e)
{
try {
// create a file
File u = new File("f:\image.png");
Desktop d = Desktop.getDesktop();
d.open(u);
}
catch (Exception evt) {
JOptionPane.showMessageDialog(this, evt.getMessage());
}
}
}
```
输出:
Program to open a file for editing
```java
// Java Program to open a file for editing
import java.awt.;
import javax.swing.;
import java.awt.event.;
import java.io.;
import java.net.*;
class desk extends JFrame implements ActionListener {
// frame
static JFrame f;
// Main Method
public static void main(String args[])
{
desk d = new desk();
// create a frame
f = new JFrame("desktop");
// create a panel
JPanel p = new JPanel();
// create a button
JButton b = new JButton("launch");
// add Action Listener
b.addActionListener(d);
p.add(b);
f.add(p);
f.show();
f.setSize(200, 200);
}
// if button is pressed
public void actionPerformed(ActionEvent e)
{
try {
// create a file
File u = new File("f:\sample.txt");
Desktop d = Desktop.getDesktop();
d.edit(u);
}
catch (Exception evt) {
JOptionPane.showMessageDialog(this, evt.getMessage());
}
}
}
```
输出:
Program to open a file for printing
```java
// Java Program to open a file for printing
import java.awt.;
import javax.swing.;
import java.awt.event.;
import java.io.;
import java.net.*;
class desk extends JFrame implements ActionListener {
// frame
static JFrame f;
// Main Method
public static void main(String args[])
{
desk d = new desk();
// create a frame
f = new JFrame("desktop");
// create a panel
JPanel p = new JPanel();
// create a button
JButton b = new JButton("launch");
// add Action Listener
b.addActionListener(d);
p.add(b);
f.add(p);
f.show();
f.setSize(200, 200);
}
// if button is pressed
public void actionPerformed(ActionEvent e)
{
try {
// create a file
File u = new File("f:\sample.txt");
Desktop d = Desktop.getDesktop();
d.print(u);
}
catch (Exception evt) {
JOptionPane.showMessageDialog(this, evt.getMessage());
}
}
}
```
输出: